import api from './auth.js'

// 普通用户API
export const userAPI = {
  // 获取用户个人资料
  getUserProfile: () => {
    return api.get('/user/profile')
  },

  // 更新用户个人资料
  updateUserProfile: (profileData) => {
    return api.put('/user/profile', profileData)
  },

  // 修改用户密码
  changeUserPassword: (passwordData) => {
    return api.put('/user/password', passwordData)
  },

  // 上传用户头像
  uploadUserAvatar: (formData) => {
    return api.post('/user/profile/avatar', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },

  // 获取用户统计信息（如果需要的话）
  getUserStats: () => {
    return api.get('/user/stats')
  },

  // ==================== 地址管理相关 ====================

  // 获取用户地址列表
  getUserAddressList: () => {
    return api.get('/user/addresses')
  },

  // 根据ID获取地址详情
  getAddressById: (addressId) => {
    return api.get(`/user/addresses/${addressId}`)
  },

  // 添加用户地址
  addUserAddress: (addressData) => {
    return api.post('/user/addresses', addressData)
  },

  // 更新用户地址
  updateUserAddress: (addressId, addressData) => {
    return api.put(`/user/addresses/${addressId}`, addressData)
  },

  // 删除用户地址
  deleteUserAddress: (addressId) => {
    return api.delete(`/user/addresses/${addressId}`)
  },

  // 设置默认地址
  setDefaultAddress: (addressId) => {
    return api.put(`/user/addresses/${addressId}/default`)
  },

  // 获取默认地址
  getDefaultAddress: () => {
    return api.get('/user/addresses/default')
  },

  // ==================== 收藏管理相关 ====================

  // 添加收藏
  addFavorite: (bookId) => {
    return api.post(`/user/favorites/${bookId}`)
  },

  // 取消收藏
  removeFavorite: (bookId) => {
    return api.delete(`/user/favorites/${bookId}`)
  },

  // 切换收藏状态
  toggleFavorite: (bookId) => {
    return api.post(`/user/favorites/${bookId}/toggle`)
  },

  // 检查收藏状态
  checkFavoriteStatus: (bookId) => {
    return api.get(`/user/favorites/${bookId}/status`)
  },

  // 获取收藏列表
  getUserFavorites: (params) => {
    return api.get('/user/favorites', { params })
  },

  // 获取收藏数量
  getFavoriteCount: () => {
    return api.get('/user/favorites/count')
  },

  // 清空收藏
  clearFavorites: () => {
    return api.delete('/user/favorites')
  }
}

export default userAPI
